package ihuotui.test.threadpool;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

import org.apache.commons.lang3.RandomUtils;

public class ConditionLockPrint implements Runnable {
    private Lock lock;
    private int no;
    private int mac;
    private Condition condition;

    public ConditionLockPrint(Lock lock,Condition condition, int no, int mac) {
        this.lock = lock;
        this.no = no;
        this.mac = mac;
        this.condition=condition;			
    }

    @SuppressWarnings("static-access")
    public void run() {
        lock.lock();// 得到锁
        try {
        	try {
				condition.await();
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
            try {
                Thread.currentThread().sleep(RandomUtils.nextInt(1, 5) * 1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//            if (mac==2) {
                System.out.println("mac:"+mac+" no:"+no);
//            }
        } finally {
            lock.unlock();// 释放锁
        }
    }
}
